package com.qing.service.impl;
import com.qing.domain.User;
import com.qing.service.UserService;
import com.qing.dao.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    private final UserDao userDao;

    @Autowired //自动装配注解，省略beans.xml配置文件。
    public UserServiceImpl(UserDao userDao){this.userDao=userDao;}

    @Override
    public void addUser(User user){
        if(user != null){ userDao.addUser(user);}
    }
    public void updateUserByUser(User user){
        if(user!=null){userDao.updateUserByUser(user);}
    }
    public void deleteUserByUserName(String userName){
        if(userName!=null){userDao.deleteUserByUserName(userName);}
    }
    /** 通过用户名查找用户 *@param userName 用户名 *@return 查找到的用户*/
    public User getUserByUserName(String userName){
        if(userName ==null){return null;}
        return userDao.findUserByUserName(userName);
    }
    public String getPassword(String userName){
        if(userName==null){return null;}
        return userDao.getUserPasswordByUserName(userName);
    }
    public List<User> getAllUser(){return userDao.getAllUserInfo();}

}
